<?php
//kohana项目函数库类
class project{
	
	//返回配置数组，默认配置组名:common
	public static function config($group = 'common'){
		return Kohana::$config->load($group);
	}

	//把字符串内的空格替换成通配符，用于关键字查询
	public static function keyword_separate($keywords,$pieces = '.*'){
    	$keywords = explode(' ',$keywords);
		return $pieces.implode($pieces,$keywords).$pieces;
    }

    //提供上传文件真实路径，返回文件虚拟路径
	public static function file_bootstrap($path){
		$path = trim($path,'/ ');
		if (stripos($path,project::config('config')->fileBootstrap) === 0){
			return $path;
		}
		if (stripos($path,project::config('config')->uploadDir) !== 0){
			return project::config('config')->fileBootstrap.'/'.$path;
		}
		return str_replace(project::config('config')->uploadDir,project::config('config')->fileBootstrap,$path);
	}
	
	//提供上传文件虚拟路径，返回文件真实路径
	public static function upload_realpath($path){
		$path = trim($path,'/ ');
		if (stripos($path,project::config('config')->uploadDir) === 0){
			return $path;
		}
		if (stripos($path,project::config('config')->fileBootstrap) !== 0){
			return project::config('config')->uploadDir.'/'.$path;
		}
		return str_replace(project::config('config')->fileBootstrap,project::config('config')->uploadDir,$path);
	}
}